<?php include './admin/view/header.inc.htm'; ?>

<div class="panel">
	<div class="header"><?php echo $header['title']; ?></div>
	<div class="body">
		<form method="POST" id="form" action="admin/forum-update-<?php echo $fid; ?>.htm">
			<table class="form">
				<tr>
					<th>版块名称：</th>
					<td>
						<input type="text" name="name" value="<?php echo $forum['name']; ?>" style="width: 150px" placeholder="板块名称" />
					</td>
				</tr>
				<tr>
					<th>排序：</th>
					<td><input type="text" name="rank" value="<?php echo $forum['rank']; ?>"style="width: 50px" placeholder="0" /> <i>倒序</i></td>
				</tr>
				<!-- 预留
				<tr>
					<th>主题分类</th>
					<td>
						
					</td>
				</tr>
				-->
				<tr>
					<th>版块介绍：</th>
					<td><textarea name="brief" id="brief" rows="3" style="width: 100%; max-width: 100%; height:200px"><?php echo $forum['brief']; ?></textarea></td>
				</tr>
				<tr>
					<th>SEO 标题：</th>
					<td><input type="text" name="seo_title" value="<?php echo $forum['seo_title']; ?>" /></td>
				</tr>
				<tr>
					<th>SEO 关键词：</th>
					<td><input type="text" name="seo_keywords" value="<?php echo $forum['seo_keywords']; ?>" /></td>
				</tr>
				<tr>
					<th valign="top">权限控制：<br><i>用户组 x 版块</i></th>
					<td>
						<p><label><input type="checkbox" name="accesson" id="accesson" value="1"<?php echo ($forum['accesson'] ? ' checked' : ''); ?> />启用</label></p>
						<table class="tborder maxwidth" id="accesslist" <?php echo ($forum['accesson'] ? '' : 'style="display: none;"'); ?>>
							<tr align="center">
								<th width="80">全选</th>
								<th width="150">用户组</th>
								<th width="100">允许看帖</th>
								<th width="100">发主题</th>
								<th width="100">回贴</td>
								<th width="100">喜欢</th>
								<th width="100">下载</th>
							</tr>
							<?php foreach ($accesslist as $group) { ?>
							<tr align="center">								
								<td><input type="checkbox" name="checkall" /></td>
								<td><?php echo $group['name']; ?></td>
								<td><input type="checkbox" name="allowread[<?php echo $group['gid']; ?>]" value="1"<?php echo ($group['allowread'] ? 'checked' : ''); ?> /></td>
								<td><input type="checkbox" name="allowthread[<?php echo $group['gid']; ?>]" value="1"<?php echo ($group['allowthread'] ? 'checked' : ''); ?> /></td>
								<td><input type="checkbox" name="allowpost[<?php echo $group['gid']; ?>]" value="1"<?php echo ($group['allowpost'] ? 'checked' : ''); ?> /></td>
								<td><input type="checkbox" name="allowagree[<?php echo $group['gid']; ?>]" value="1"<?php echo ($group['allowagree'] ? 'checked' : ''); ?> /></td>
								<td><input type="checkbox" name="allowdown[<?php echo $group['gid']; ?>]" value="1"<?php echo ($group['allowdown'] ? 'checked' : ''); ?> /></td>
							</tr>
							<?php } ?>
						</table>
					
					</td>
				</tr>
				<tr>
					<th>版主用户名：<br><i>多个逗号隔开</th>
					<td><input type="text" name="modnames" value="" /></td>
				</tr>
				<tr>
					<th>版主ID：<br><i>多个逗号隔开</th>
					<td><input type="text" name="moduids" value="<?php echo $forum['moduids']; ?>" /></td>
				</tr>
				<tr>
					<th>&nbsp;</th>
					<td>
						<button type="submit" id="submit" loading-text="正在提交" class="blue big">确定</button>
						<a href="forum-<?php echo $fid; ?>.htm" target="_blank">查看版块</a>
					</td>
				</tr>
			</table>
		</form>
	</div>
</div>

<?php include './admin/view/footer.inc.htm'; ?>

<link rel="stylesheet" type="text/css" href="xneditor/editor.css" />
<script src="xneditor/editor.js"></script>

<script>

var editor = new $.XNEditor({textarea: 'brief', image_upload_url:'admin/article-uploadimage.htm', file_upload_url:'admin/article-uploadimage.htm'});

var jsubject = $("#subject");
var jcateid = $("#cateid");
var jform = $("#form");
var jsubmit = $("#submit");
var jmessage = $('#message');
var jaccesson = $('#accesson');
var jaccesslist = $('#accesslist');

jaccesslist.find('tr').each(function(k, v) {
	var jtr = $(v);
	jtr.find('td').eq(0).find('input[type="checkbox"]').on('click', function() {
		jtr.find('input[type="checkbox"]').prop('checked', $(this).prop('checked'));
	});
});
jform.on('submit', function(){
	var postdata = jform.serialize();
	jsubmit.button('loading');
	$.xpost(jform.attr('action'), postdata, function(code, message) {
		if(code == 0) {
			//editor.clear();
			jsubmit.text(message);
			setTimeout(function(){
				jsubmit.button('reset');
			}, 1000);
			return;
		} else if(code == 1) {
			jcateid.popover(message).focus();
		} else if(code == 2) {
			jsubject.popover(message).focus();
		} else if(code == 3) {
			alert(message);
			//editor.jeditor.popover(message).focus();
		} else {
			$.alert(message);
		}
		jsubmit.button('reset');
	});
	return false;
});
jaccesson.on('click', function() {jaccesslist.toggle()});

// 斑竹ids
var jmoduids = jform.find('input[name="moduids"]');
var jmodnames = jform.find('input[name="modnames"]');

var getname = function(v) {
	$.xget('admin/forum-getname-'+v+'.htm', function(code, message) {
		if(code == 0) {
			jmodnames.val(message);
		} else if(code == 1) {
			jmoduids.popover(message);
		} else {
			jmoduids.popover(message);
		}
	});		
}
jmoduids.on('keyup', function(e) {if(e.keyCode == 188) getname(this.value);});
jmoduids.on('blur', function(e) {getname(this.value);});

var getuid = function(v) {
	$.xget('admin/forum-getuid-'+xn_urlencode(v)+'.htm', function(code, message) {
		if(code == 0) {
			jmoduids.val(message);
		} else if(code == 1) {
			jmodnames.popover(message);
		} else {
			jmodnames.popover(message);
		}
	});	
}
jmodnames.on('keyup', function(e) {if(e.keyCode == 188) getuid(this.value);});
jmodnames.on('blur', function(e) {getuid(this.value);});

getname(jmoduids.val());
</script>